<template>
  <el-form
    :model="addEditForm"
    ref="addEditForm"
    label-width="95px"
    label-position="left"
    class="pg-shaohuo-person-add-edit-admin-group">
    <el-dialog
      :title="`${type}用户组`"
      :before-close="beforeDialogClose"
      :visible.sync="dialogVisible"
      width="50%">

      <!-- 表单主题
      -------------------------- -->
      <el-form-item 
        label="用户组名称"
        prop="title"
        :rules="{ required: true, message: '请输入用户组名称', trigger: 'blur' }">
        <el-input v-model="addEditForm.title"></el-input>
      </el-form-item>
      
      <!-- 底部按钮区
      -------------------------- -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogClose">取 消</el-button>
        <el-button type="primary"
          @click="submitForm"
          :loading="loadingBtn === '确定'">确 定</el-button>
      </span>
    </el-dialog>
  </el-form>
</template>

<script>
import { SettingPermissionService } from 'services/Api'
import {
  btnLoadingMixin,
  formAddEditMixin,
  dialogCoreMixin
} from 'services/Public'
import { mapState } from 'vuex'

export default {
  mixins: [
    btnLoadingMixin,
    formAddEditMixin,
    dialogCoreMixin
  ],
  data () {
    return {
      addEditForm: {
        title: ''
      }
    }
  },
  computed: {
    ...mapState([ 'acc_id' ]),
    // 添加参数
    addParam () {
      return {
        acc_id: this.acc_id,
        title: this.addEditForm.title
      }
    },
    // 修改参数
    alterParam () {
      return {
        acc_id: this.acc_id,
        group_id: this.editData.group_id,
        title: this.addEditForm.title
      }
    }
  },
  methods: {
    // 关闭弹窗前重置表单
    beforeDialogClose (done) {
      if (done) done()
      this.isEditing = false
      this.resetForm()
      this.addEditForm = {
        title: ''
      }
    },
    // formAddEditMixin需要 - 编辑时将传入的源数据写入当前表单
    editDataHandler (v) {
      this.addEditForm.title = v.title || ''
    },
    // formAddEditMixin需要 - 提交成功后的操作
    afterSubmitSuccess () {
      this.dialogComplete()
    },
    // 添加接口
    currentAddApi () {
      return SettingPermissionService.addAdminGroup(this.addParam)
    },
    // 编辑接口
    currentEditApi () {
      return SettingPermissionService.editAdminGroup(this.alterParam)
    }
  }
}
</script>

<style lang="scss">
@import "src/styles/config/views.scss";

@include b(shaohuo-person-add-edit-admin-group) {
  .el-form-item__content > .el-input {
    width: 80%;
  }
}
</style>
